<%--
  Created by IntelliJ IDEA.
  User: zhangjie
  Date: 2018/9/18
  Time: 2:53 PM
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jsp/component/common.jsp" %>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" ></meta>
    <title>血糖筛查</title>
    <link rel="stylesheet" href="${frames}/css/lib/bootstrap.min.css" type="text/css">
    <link rel="stylesheet" href="${frames}/css/lib/bootstrap-datetimepicker.min.css" type="text/css">
    <link rel="stylesheet" href="${frames}/css/lib/dataTables.bootstrap.css" type="text/css">
    <%--<link rel="stylesheet" href="../assets/css/views/modules/_common.scss">--%>
    <link rel="stylesheet" href="${newframe}/css/base/base.css" type="text/css">
    <link rel="stylesheet" href="${assets}/css/views/bloodScreening.css">
    <link rel="stylesheet" href="${assets}/css/views/department/departmentMgr.css">
    <script src="../assets/js/views/vue.min.js"></script>
    <script src="${js}/jquery-1.9.1.min.js"></script>
    <script src="${frames}/Chronic/laydate/laydate.js"></script>
    <%@ include file="/WEB-INF/jsp/component/commonBottom.jsp" %>
    <style>
        .color{
            margin:0 !important;
        }
        .first_news span{
            font-family:MicrosoftYaHei-Bold;
            font-weight:normal;
            font-stretch:normal;
            letter-spacing:0px;
        }
        .btn{
            float:right ;
            width:100px;
            font-size:16px;
            line-height:28px;
            background:#35acfd !important;
            margin-right:15px !important;
            padding:0 !important;
        }
        .infor div span{
            color:#666;
        }
        .infor .other span{
            width:40.7%;
            margin-right:5.36%;
        }
        #example_paginate{
            margin-top:15px;
            width:100%;
            text-align: center;
        }
        #mytool{
            width:96%;
        }
        .highMax{
            color:#ff1319;
        }
    </style>
</head>
<body>
    <div>
        <%@ include file="../../breadline.jsp" %>
    </div>
    <div id="main" class="wrap">
        <div style="width:100%;">
            <div>
                <%@ include file="../../personalnews.jsp" %>
            </div>
            <div class="illness">
                <div class="tableWrap">
                    <div style="margin-left:20px;padding-top:20px;">
                        <h3 style="margin-bottom:16px;">筛查记录</h3>
                    </div>
                    <div class="form">
                        <div id="date" style="float: left">
                            <label>时间:</label>
                            <input id="beginDate" type="text" class="lay-date" placeholder="起始时间" readonly>
                            <label> — </label>
                            <input id="endDate" type="text" class="lay-date" placeholder="截止时间" readonly>
                        </div>
                        <button class="search" id="query" onclick="refreshTable();">搜索</button>
                    </div>
                    <div class="content" style="padding-bottom:40px;">
                        <div id="tablepart">
                            <table id="example" class="display" cellspacing="10" width="100%">
                                <thead>
                                <tr style="background:#e6e6e6;">
                                    <th></th>
                                    <th>筛查时间</th>
                                    <th>血糖类型</th>
                                    <th>血糖值(mmol/L)</th>
                                    <th>管理方式</th>
                                </tr>
                                </thead>
                            </table>
                            <%--<p v-show="test" style="text-align:center;line-height:40px;font-size:14px;">暂无数据</p>--%>
                        </div>
                    </div>
                    <div class="loading" style="display: none;">
                        <img src="${newframe }/images/slidebar/loading.gif" class="loadingImg">
                    </div>
                </div>

            </div>
        </div>
    </div>
    <script>
        var vm = new Vue({
            el: "#main",
            data: {
                infor: [],//病人基本信息data
                id: '',
                idCard: '',
                ispatient: '',
                measure: '',
                Symptom: '',
                tachycardia: '',
                sudden: '',
                type:'',
                synchronous:false,
                btnText:'',
                dis:false
            },
            methods:{
                //修改病人基本信息
                addDevice:function(){
                    let that = this;
                    window.parent.showNewModelIframe("${URL_PATIENT_PATIENT}?id="+that.infor.id+'&diseasesType='+that.type,800,650);
                },
                Synchronous(e){
                    let that = this
                    $.ajax({
                        url:'${URL_PATIENT_UPDATEPATIENT}',
                        data:{
                            id:that.infor.id,
                            synchronization:'1'
                        },
                        type:'post',
                        dataType:'json',
                        success:function(data){
                            console.log(data)
                            if(data.success){
                                e.target.disabled = true;
                                e.target.innerText = '正在同步'
                                that.setTime()
                            }else{
                                window.parent.showNewModelIframe('${URL_COMMON_TOTIPS}?title='+data.msg,300,200)
                            }
                        }
                    })
                },
                setTime(){
                    let that = this
                    setInterval(function(){
                        $.ajax({
                            url:'${URL_PATIENT_UPDATEPATIENT}',
                            data:{
                                id:that.infor.id,
                                synchronization:'1'
                            },
                            type:'post',
                            dataType:'json',
                            success:function(data){

                            }
                        })
                    },10000)
                }
            },
            mounted() {
                let that = this;
                var href = location.search.split('?')[1];
                var arr = href.split('&')[0];
                var url = arr.split('=')[1];
                var add = location.search.split('?')[1].split('&')
                that.type = location.search.split('?')[1].split('&')[add.length -1 ].split('=')[1]
                // 获取病人基本信息
                $.ajax({
                    url:"${URL_PATIENT_PATIENTINFO}",
                    type:'post',
                    dataType: "json",
                    data:{
                        idCard:"${idcard}"
                    },
                    success: function(data) {
                        that.infor = data.data;
                        var href = that.infor.diseasesType
                        that.infor.diseasesType = Type(that.infor.diseasesType)
                        that.id=that.infor.id;
                        that.idCard=url;
                    }
                })

            }
        })
        $(document).ready(function() {
            initTable();
            // 初始化日历
            initLayDate('#beginDate');
            initLayDate('#endDate');
        })
        function initTable() {
            var url="${URL_SCREENING_BSLIST}?idCard="+"${idcard}";
            table = $('#example').DataTable({
                "dom": "<'row'<'#mytool.col-xs-10'><'col-xs-6'f>r>" +
                    "t" +
                    "<'row'<''i><''p>>",
                "bFilter": false,//去掉搜索框
                "bAutoWidth": true, //自适应宽度
                "info": false,
                "bSort": false,
                "sPaginationType" : "full_numbers",
                "ordering": false,//是否允许Datatables开启排序
                "bProcessing" : true,
                "bServerSide" : true,
                "searching" : false, //去掉搜索框方法一
                'lengthChange' : false,
                "oPaginate":false,
                "sAjaxSource":url,
                "sAjaxDataProp": "dataList",//查询后，返回的集合
                "fnServerData": function ( sSource, aoData, fnCallback ) {
                    aoData.push(
                        {
                            "name" : "startTime",
                            "value" : $("#beginDate").val()
                        },{
                            "name" : "endTime",
                            "value" : $("#endDate").val()
                        }
                    );
                    $.ajax( {
                        "dataType": 'json',
                        "url": sSource,
                        "type":'post',
                        "data":aoData,
                        "success": function(resp){
                            fnCallback(resp)
                            console.log(resp);
                        }
                    });
                },
                "aoColumns" : [{
                    "targets": 0,
                    "data": null,
                    "fnCreatedCell" : function(nTd, sData, oData, iRow, iCol) {
                        $(nTd).html(
                            ''
                            + '&nbsp;&nbsp;<input name="id" class="check_id" id = "'+oData.id + '" value="'
                            + oData.id
                            + '" type="checkbox"><label for='+oData.id+'></label>'
                            + '');
                    }
                },{
                    "mDataProp" : "screeningTime"
                },{
                    "targets": 2,
                    "data": null,
                    "fnCreatedCell" : function(nTd, sData, oData, iRow, iCol) {
                        if(oData.bloodSugarType=='2'){
                            $(nTd).html(
                                ''
                                + '<span>餐后血糖</span>'
                                + '');
                        }else{
                            $(nTd).html(
                                ''
                                + '<span>空腹血糖</span>'
                                + '');
                        }
                    }
                },{
                    "targets": 3,
                    "data": null,
                    "fnCreatedCell" : function(nTd, sData, oData, iRow, iCol) {
                        if(oData.bloodSugarType=='1'&&parseInt(oData.bloodSugarValue)>=parseInt(oData.beforeMaxValue)){
                            $(nTd).html(
                                ''
                                + '<span class="highMax" >'+oData.bloodSugarValue+ '</span>'
                                + '');
                        }else if (oData.bloodSugarType=='1'&&parseInt(oData.bloodSugarValue)<parseInt(oData.beforeMaxValue)) {
                            $(nTd).html(
                                ''
                                + '<span class="" >'+oData.bloodSugarValue+ '</span>'
                                + '');
                        }else if (oData.bloodSugarType=='2'&&parseInt(oData.bloodSugarValue)>=parseInt(oData.afterMaxValue)){
                            $(nTd).html(
                                ''
                                + '<span class="highMax" >'+oData.bloodSugarValue+ '</span>'
                                + '');
                        }else {
                            $(nTd).html(
                                ''
                                + '<span>'+oData.bloodSugarValue+ '</span>'
                                + '');
                        }
                    }
                },{
                    "targets": 4,
                    "data": null,
                    "fnCreatedCell" : function(nTd, sData, oData, iRow, iCol) {
                        if(oData.managementType=='2'){
                            $(nTd).html(
                                ''
                                + '<span>强化管理</span>'
                                + '');
                        }else{
                            $(nTd).html(
                                ''
                                + '<span>一般管理</span>'
                                + '');
                        }
                    }
                }],
                "oLanguage": {//插件的汉化
                    "sLengthMenu": "32",
                    "sInfoEmpty" : "没有数据",
                    "sInfoFiltered" : "(从 _MAX_ 条数据中检索)",
                    "oPaginate" : {
                        "sFirst" : "",
                        "sPrevious" : "<b>上一页<b>",
                        "sLast" : "",
                        "sNext" : "<i>下一页</i>"

                    },
                    "sZeroRecords" : "没有检索到数据",
                    "sProcessing" : "<img src='' />",
                    "sSearch" : "搜索"
                },
                "initComplete" : function() {
                    $("#mytool")
                        .append(
                            '<button id="delete_butt" type="button" onclick="deleteInstr()" style="float:right">删除</button>');
                    $("#mytool")
                        .append(
                            '<button id="update_butt" type="button" onclick="updateInfo()" style="float:right">修改</button>');
                    $("#mytool")
                        .append(
                            '<button id="delete_butt" type="button" onclick="addInfo()" style="float:right">新增</button>');
                }

            });
        }
        function initLayDate(id) {
            laydate({
                elem: id,
                istime: true,
                format: 'YYYY-MM-DD',
                choose: function (dates) { //选择好日期的回调
                    // initTablePatient();
                }
            })
        }
        function updateInfo(obj){
            var checkedArray = getCheckedArray();
            var pAge=sessionStorage.getItem('age');
            var input = $('.check_id');

            if (checkedArray.length != 1) {
                alert("请勾选一条数据修改");
                return;
            }else{
                parent.showSrc('${URL_SCREENING_BSSCREENING}?idcard=' + '${idcard}'+ '&id=' +checkedArray[0]);

            }

        }
        function addInfo() {
            parent.showSrc('${URL_SCREENING_BSSCREENING}?idcard=' + '${idcard}');
        }
        function deleteInstr() {
            var checkedArray = getCheckedArray();
            var ids = "";
            if (checkedArray.length == 0) {
                alert("请勾选至少一项数据");
                return;
            } else {
                for (var i = 0; i < checkedArray.length; i++) {
                    ids += checkedArray[i] + ",";
                }
                ids = ids.substring(0, ids.length - 1);
            }
            var r = confirm("确定要删除勾选的数据吗?");
            if (r == true) {
                $.ajax({
                    url : '${URL_SCREENING_DELETEBS}',//删除地址
                    dataType : 'json',
                    type : 'post',
                    data : {
                        ids : ids
                    },
                    async : false, //默认为true 异步
                    error : function() {
                    },
                    success : function(data) {

                        if (!data.success) {
                            alert("刪除失敗，失敗原因：" + data.msg);
                        }
                        refreshTable();
                    }
                });
            }
        }
        function getCheckedArray() {
            var checkedArray = [];
            $("input[name='id']").each(function() {
                if (this.checked) {
                    checkedArray.push(this.value);
                }
            });
            return checkedArray;
        }

    </script>
</body>
</html>
